package com.cloud.bc.config;

import com.cloud.bc.model.enums.CookieConst;
import com.cloud.common.util.CookieUtils;
import lombok.SneakyThrows;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PlatformInterceptors implements HandlerInterceptor {

    /**
     * 在请求处理之前进行调用（Controller方法调用之前）
     */
    @SneakyThrows
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {

        String requestURI = request.getRequestURI();
        if (requestURI.contains("/ajax/") ||
                requestURI.contains("/error") ||
                requestURI.contains("common/about")) {
            return true;
        }
        if (requestURI.contains("/m")) {
            //是m站
            CookieUtils.setCookie(request, response, CookieConst.platformCookie, "m");
        } else {
            //是pc站
            CookieUtils.setCookie(request, response, CookieConst.platformCookie, "pc");
        }
        return true;
    }
}
